# coding:utf8



# 生成器函数
def fn():
    print 'hah'
    yield 1
    print 'xix'
    yield 2
    print 'heh'
    yield 3


g = fn()
# g.next()
# g.next()
# g.next()


for x in g:
    print x


# 实现一个可迭代对象的类，他能迭代出给定范围内所有的素数
class Primes():
    def __init__(self, start, end):
        self.start = start
        self.end = end

    def isPrime(self, k):
        if k < 2:
            return False
        for i in range(2, k):
            if k % i == 0:
                return False
        return True

    def __iter__(self):
        for k in range(self.start, self.end + 1):
            if self.isPrime(k):
                yield k


for x in Primes(0, 20):
    print x
